package controllers;

import handler.GetHandler;
import handler.PostHandler;
import play.mvc.BodyParser;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.index;

public class Application extends Controller {

    public static Result index() {
        return ok(index.render("Your new application is ready."));
    }

    public static Result doGet(int action) {
        return GetHandler.handleAction(action, request());
    }

    @BodyParser.Of(BodyParser.Json.class)
    public static Result doPost(int action) {
        return PostHandler.handleAction(action, request());
        // PostHandler handler = null;
        // JsonNode requestJson = request().body().asJson();
        // switch (action) {
        // case PostAction.REGISTER: {
        // handler = new RegisterPostHandler(requestJson);
        // break;
        // }
        // case PostAction.LOGIN: {
        // handler = new LoginPostHandler(requestJson);
        // break;
        // }
        // case PostAction.ADD_ITEM: {
        // handler = new AddItemPostHandler(requestJson);
        // break;
        // }
        // case PostAction.RECORD: {
        // handler = new RecordItemPostHandler(requestJson);
        // break;
        // }
        // default:
        // return ok(ResponseUtil.failNotSupportAction(action));
        // }
        //
        // handler.execute();
        //
        // if (handler.isSuccess()) {
        // return ok(ResponseUtil.success(action, handler.getResponseData()));
        // } else {
        // return ok(ResponseUtil.fail(action, handler.getError()));
        // }
    }
}
